package utils;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Transform {
    /**
     * 字符串转日期
     * @param str
     * @return
     */
    public static Date stringToDate(String str){
        Date date = null;
        try {
            date = new SimpleDateFormat().parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * beanUtils格式转化器
     */
    public static void beanUtilsConvert(){
        //String -->date
        DateConverter converter = new DateConverter();
        converter.setPattern(new String("yyyy-MM-dd"));
        ConvertUtils.register(converter,Date.class);
    }
}
